<?php

/**
 * @filename ShowAction.class.php 
 * @encoding UTF-8 
 * @author yuzhiyuan <307090870@qq.com>
 * @copyright copyright 2013 (c) Emagsoftware Technology Co., Ltd. All Rights reserved.
 * @license ……
 * @datetime 2013-6-23  0:41:33
 * @version 1.0
 * @Description
  */
class ShowAction extends BaseAction {
    public function index(){
    	$id = I('id','intval',0);
        $key = 'post_info_'.$id;
        $data = S($key);        
        $db = M('Post');
        if(false === $data){
            $data = $db->join("blg_user ON blg_post.u_id = blg_user.id")->join("blg_cate ON blg_post.c_id = blg_cate.id")->where('blg_post.id = '.$id. ' AND blg_post.is_del = 0')->field("blg_post.id as aid,blg_post.title as atitle,blg_post.id as aid,blg_post.c_id as acid,blg_post.add_time as aaddtime,blg_user.nickname as bnickname,blg_cate.c_name as c_name,blg_post.content as acontent,blg_post.titlepic as atitlepic")->find();
            S($key,$data);      
            unset($db);
        }
        unset($key);
        $key = "post_comment_info".$id;
        $cmt = S($key);
        if(false === $cmt){
            $db = M('Comment');
            $cmt = $db->field('blg_comment.id as id,blg_comment.content as content,blg_comment.add_time as add_time,blg_comment.u_id as u_id,blg_comment.parent_id as parent_id,blg_comment.u_id as u_id,blg_user.nickname as nickname,blg_user.web_site as web_site,blg_user.avatar_picture as avatar_picture')->join("blg_user ON blg_comment.u_id = blg_user.id")->where("blg_comment.p_id = ".$id." and blg_comment.is_verify = 1")->select();
            S($key,$cmt);
            unset($db);
        }
     //   dump($cmt);
        import('Class.Comment',APP_PATH);
        $cmt = Comment::dealCmts($cmt);
        $this->assign('comments',$cmt); 
        $this->assign('post',$data);
        $this->display();
    }
    
    public function setClickInc(){
        $id = (int)$_GET['id'];
        $db = M('Post');     
        $where['id'] = $id;
        if('1' != cookie('has_view_post_' . $id)){
            if($db->where($where)->setInc('click',1)){
                cookie('has_view_post_' . $id,'1',3600 * 24);
            }
        }
        $click = $db->where($where)->getField('click');   
        echo "document.write('浏览(" . $click . ")');";
    
    }
    public function getCmtNum(){
        $id = (int)$_GET['id'];
        $db = M('Comment');     
        $where['p_id'] = $id;   
        $where['is_verify'] = 1; 
        $num = $db->where($where)->count();   
        echo "document.write('" . $num . "');";        
    
    }
}